/**
 * 
 */
package leetCode;

/**
 * @author zhongfang
 *
 */
public class SecondMinimumNodeInaBinaryTree {
	public class TreeNode {
		int val;
		TreeNode left;
		TreeNode right;

		TreeNode(int x) {
			val = x;
		}
	}

	int min = Integer.MAX_VALUE;

	public int findSecondMinimumValue(TreeNode root) {
		findSecondMinimumValue(root, root.val);
		return min == Integer.MAX_VALUE ? -1 : min;
	}

	private void findSecondMinimumValue(TreeNode root, int val) {
		if (root == null) {
			return;
		}
		if (root.val != val) {
			min = Math.min(min, root.val);
		}
		findSecondMinimumValue(root.left, val);
		findSecondMinimumValue(root.right, val);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
